package test;

public class T {

	public static void main(String[] args) {
		NewList ne = new NewList();
		String[] src= {"0","1","2","3","4","5"};
		
		ne.initList(src);
		ne.print();
		ne.delete(ne.getNodeAt(0));
		ne.print();
		ne.delete(ne.getNodeAt(2));
		ne.print();
		ne.delete(ne.getNodeAt(3));
		ne.print();
	}
}
 class Node{
	Node next;
	String data;
}
class NewList{
	Node head;
	
	public void initList(String[] data){
		int length =data.length;
		Node element = null;
		Node current = null;
		for(int i=length-1;i>=0;i--){
			element = new Node();
			element.next = current;
			element.data = data[i];
			current = element;
		}
		head = element;
	}
	
	
	public Node getNodeAt(int pos){
		if(head == null)
			return null;
		int index = 0;
		Node element = head;
		while(element!=null){
			if(pos == index){
				return element;
			}
			element = element.next;
			index++;
		}
		return null;
	}
	
	public void delete(Node tobedeleted){
		if(tobedeleted == null)
			System.out.println("tobedeleted is empty");
		Node next = tobedeleted.next;
		tobedeleted.data = next.data;
		tobedeleted.next = next.next;
		
	}
	
	public void print(){
		if(head == null)
			System.out.println("this is empty");
		Node element = head;
		while(element!=null){
			System.out.print(element.data+"-");
			element = element.next;
		}
		System.out.println();
	}
	
}
